<%@ page language="java" import="java.sql.*" contentType="text/html;charset=UTF-8" %>
<%/*@ page language="java" import="java.sql.*" contentType="text/html;charset=KSC5601" */%>

<HTML>
<HEAD><TITLE>▒▒ 게시판 ▒▒</TITLE></HEAD>
<BODY>

<%
int intIdx = Integer.parseInt(request.getParameter("idx"));
String sPwd = request.getParameter("password");


String DB_URL = "jdbc:mysql://localhost:3306/bbs?useUnicode=true&characterEncoding=utf8";
String DB_USER = "root";
String DB_PASSWORD = "root";

Connection conn = null;
Statement stmt = null;
ResultSet result = null;

String query = "SELECT PASSWORD FROM GUEST WHERE IDX='"+intIdx+"'";
String query1 = "DELETE FROM GUEST WHERE IDX='"+intIdx+"'";        
String query2 = "UPDATE GUEST SET IDX=IDX-1 WHERE IDX > "+intIdx;
 
		
	try {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(DB_URL,DB_USER,DB_PASSWORD);
		stmt = conn.createStatement();
		result = stmt.executeQuery(query);
		
		if(result.next()){
			if(sPwd.equals(result.getString(1))){
				stmt.executeUpdate(query1);
				stmt.close();
				
				stmt = conn.createStatement();
				stmt.executeUpdate(query2);
				
				result.close();
				stmt.close();
				conn.close();
				
				response.sendRedirect("list.jsp");
			}
		}
		
		result.close();
		stmt.close();
		conn.close();
 
%>		
		// 입력받은 암호가 DB 암호와 일치하지 않으면 목록 내용보기로 돌아간다..
		<body onLoad="location.href='javascritp:history.go(-2)'"><!-- 여기 -->
<%			
	} catch(Exception e){e.printStackTrace();}
%>

</BODY>
</HTML>
